package com.ucitymetro.ucitymc.autosecurity.utils;
import java.util.Base64;

/**
 * 前后端数据传输加密工具类
 */
public class BASE64Utils {
    /**
     * 加密
     * @param content 加密的字符串
     * @return
     * @throws Exception
     */
    public static String encrypt(String content) throws Exception {
        try {
            return Base64.getEncoder().encodeToString(content.getBytes("UTF-8"));
        }catch (Exception e){
            throw new Exception("BASE64加密失败！错误原因："+e.getMessage());
        }
    }

    /**
     * 解密
     * @param content 解密的字符串
     * @return
     * @throws Exception
     */
    public static String decrypt(String content) throws Exception{
        try {
            return Base64.getDecoder().decode(content.getBytes("UTF-8")).toString();
        }catch (Exception e){
            throw new Exception("BASE64解密失败！错误原因："+e.getMessage());
        }
    }
}